<template>
  <div>
    <div class="head">
      <van-nav-bar title="我的评论" left-text="返回" left-arrow   @click-left="onClickLeft"/>
    </div>
    <van-empty v-if="list.length <= 0" description="您还没有评论" />

    <div class="pinglun" v-else>
      <h2>评论</h2>

      <div class="userpl" v-for="(v, b) in list" :key="b">
        <div class="userhead">
          <img src="../../assets/images/head.jpg" alt="" />
        </div>
        <div class="pl_middle">
          <span class="van-ellipsis">{{ v.username }}:{{ v.pl }}</span>
          <p class="time">{{ v.time | dateFormat }}</p>
        </div>

        <div>
          <van-button type="warning" @click="delpl(v._id)">删除</van-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  data() {
    return {
      list: [],
    };
  },
  methods: {
      onClickLeft(){
          this.$router.go(-1)
      }

      ,
    delpl(value) {
      this.$ajax
        .delpl({
          username: localStorage.getItem("username"),
          _id: value,
        })
        .then((res) => {
          if (res.type == 1) {
            Toast("删除成功");
            this.$ajax
              .FMuserpl({
                username: localStorage.getItem("username"),
              })
              .then((res) => {
                this.list = res.data;
                console.log(this.list);
              });
          }
        });
    },
  },
  mounted() {
    this.$ajax
      .FMuserpl({
        username: localStorage.getItem("username"),
      })
      .then((res) => {
        this.list = res.data;
        console.log(this.list);
      });
  },
};
</script>

<style scoped lang="scss">
.pinglun {
  background-color: #fff;
  margin: 10px 0 10px 0;
  text-align: left;
  padding: 10px;
  position: relative;
  h2 {
    font-size: 13px;
    font-weight: 600;
    line-height: 40px;
  }

  .userhead {
    width: 0.8rem;
    height: 0.8rem;
    flex: 1;
    img {
      width: 100%;
      height: 100%;
    }
  }

  .userpl {
    display: flex;
    align-content: center;
    margin-top: 40px;
  }

  .pl_middle {
    display: flex;
    width: 100px;
    margin-left: 5px;
    flex: 10;
    align-items: center;
    span {
      flex-wrap: nowrap;
      margin-left: 5px;
    }
    .all_pl {
      width: 200px;
      display: block;
    }
  }

  .time {
    margin-left: 20px;
  }
}

::v-deep .van-button--warning {
  height: 30px;
}
</style>